﻿using Dapper.Model;
using Microsoft.Extensions.Options;
//using Microsoft.Extensions.Options;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace Dapper.Service
{
    public class DBConfig
    {
        private static string DefaultSqlConnectionString = "server=127.0.0.1;database=leon;user=root;pwd=root;SslMode=none;";

        //private readonly static IOptions<AppSettingModel> _appSetting;
        //public DBConfig(IOptions<AppSettingModel> appSetting)
        //{
        //    _appSetting = appSetting;
        //}

        public static IDbConnection GetSqlConnection(string sqlConnectionString = "")
        {
            if (string.IsNullOrEmpty(sqlConnectionString))
            {
                //sqlConnectionString = System.Configuration.ConfigurationManager.AppSettings["mysqlServer"].ToString();
                sqlConnectionString = DefaultSqlConnectionString;
                //sqlConnectionString = _appSetting.Value.mysqlServer;
            }
            IDbConnection conn = new MySqlConnection(sqlConnectionString);
            conn.Open();
            return conn;
        }
    }
}
